// by Xeno
#define THIS_FILE "fn_pnselchanged.sqf"
#include "x_setup.sqf"
private ["_selection", "_selectedIndex"];

disableSerialization;

_selection = _this select 0;

_selectedIndex = _selection select 1;

if (_selectedIndex == -1) exitWith {};

if (GVAR(show_player_namesx) != _selectedIndex) then {
	GVAR(show_player_namesx) = _selectedIndex;
	switch (GVAR(show_player_namesx)) do {
		case 0: {
			if (x_show_pname_hud) then {
				x_show_pname_hud = false;
				if (GVAR(phudraw3d) != -1) then {
					removeMissionEventHandler ["Draw3D", GVAR(phudraw3d)];
					GVAR(phudraw3d) = -1;
				};
				["player_hud2", {call FUNC(player_name_huddo2)},0] call FUNC(addPerFrame);
			};
			systemChat (localize "STR_DOM_MISSIONSTRING_887");
		};
		case 1: {
			if (!x_show_pname_hud) then {
				x_show_pname_hud = true;
				if (GVAR(phudraw3d) != -1) then {
					removeMissionEventHandler ["Draw3D", GVAR(phudraw3d)];
					GVAR(phudraw3d) = -1;
				};
				GVAR(phudraw3d) = addMissionEventHandler ["Draw3D", {call FUNC(player_name_huddo)}];
			};
			systemChat (localize "STR_DOM_MISSIONSTRING_888");
		};
		case 2: {
			if (!x_show_pname_hud) then {
				x_show_pname_hud = true;
				if (GVAR(phudraw3d) != -1) then {
					removeMissionEventHandler ["Draw3D", GVAR(phudraw3d)];
					GVAR(phudraw3d) = -1;
				};
				GVAR(phudraw3d) = addMissionEventHandler ["Draw3D", {call FUNC(player_name_huddo)}];
			};
			systemChat (localize "STR_DOM_MISSIONSTRING_890");
		};
	};
};